package com.example.jwt.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.jwt.demo.aop.InvokeLog;
import com.example.jwt.demo.entity.ResponseResult;
import com.example.jwt.demo.entity.User;
import com.example.jwt.demo.mapper.UserMapper;
import com.example.jwt.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> findUserByUsername(User users) {
        System.out.println(users.getUsername());
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("username",users.getUsername());
        List users1=  userMapper.selectList(wrapper);
        users1.forEach((item)->{
            System.out.println(item);
        });
        return users1;
    }

    @Override
    public User findUserById(int userId) {
        return userMapper.selectById(userId);
    }

    @Override
    @Transactional
    @InvokeLog
    public ResponseResult insertUser(User user) {
//        save(user);
//        System.out.println(1/0);
//        save(user);
        return ResponseResult.okResult(200,"成功");
    }

}
